package com.jfinal.kit;

import java.util.Arrays;

public class SqlAppender {

	private StringBuffer sqlbuff = new StringBuffer();
	private Object[] params;

	public SqlAppender() {

	}

	public SqlAppender(String sql, Object... paras) {
		sqlbuff = new StringBuffer(sql);
		params = paras;
	}

	public SqlAppender append(String sql) {
		sqlbuff.append(sql);
		return this;
	}

	public SqlAppender append(String sql, Object... paras) {
		sqlbuff.append(sql);
		if (params != null) {
			params = concat(params, paras);
		} else {
			params = paras;
		}
		return this;
	}

	public static <T> T[] concat(T[] first, T[] second) {
		T[] result = Arrays.copyOf(first, first.length + second.length);
		System.arraycopy(second, 0, result, first.length, second.length);
		return result;
	}

	public String getSqlString() {
		return sqlbuff.toString();
	}

	public Object[] getSqlParams() {
		return params;
	}

}
